package newRegFrm.service;

import newRegFrm.dao.UserDao;
import newRegFrm.model.User;
import user.c3p0Util;

import java.sql.Connection;
import java.sql.SQLException;

public class UserService {
    public UserDao userDao = new UserDao();
    public User user = new User();
    // 注册新员工
    public boolean register(User employee) {
        Connection conn = null;
        try {
            conn = c3p0Util.getConnection();
            int result = UserDao.addUser(conn, employee);
            // 明确判断返回值
            if (result == 1) {
                return true;
            } else if (result == 0) {
                // 用户名已存在
                return false;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            c3p0Util.closeConnection(conn);
        }
        return false;
    }
}
